require('babel-polyfill');
var html2canvas = require('html2canvas');
var saveAs = require('file-saver').saveAs;
function HtmlLoader() {

}

HtmlLoader.prototype = {
    load: function (dom, fileName) {
        var self = this;
        var p = new Promise(function (resolve) {
            if (!fileName) {
                new Error('请输入文件名');
            }
            html2canvas(dom).then(function (canvas) {
                canvas.toBlob(function (blob) {
                    saveAs(blob, fileName);
                    resolve();
                })
            })
        });
        return p;
    },
    save: function (dom) {
        var dataUrl = null, self = this;
        var p = new Promise(function (resolve) {
            html2canvas(dom).then(function (canvas) {
                dataUrl = canvas.toDataURL();
                resolve(dataUrl);
            })
        });
        return p;
    }
}
//检测模块化方式
if(typeof module!=='object' && typeof define!=='function'){
    window.HtmlLoader=HtmlLoader;
};
module.exports = HtmlLoader;
